/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package br.com.menosehmais.persistence;

import br.com.caelum.vraptor.ioc.Component;
import br.com.menosehmais.framework.persistence.DaoJpa2;
import br.com.menosehmais.model.ContaDO;
import br.com.menosehmais.model.PortletDO;
import br.com.menosehmais.model.PortletOpinionDO;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

/**
 *
 * @author RafaelRosa
 */
@Component
public class PortletOpinionDAO extends DaoJpa2<PortletOpinionDO> {

    public PortletOpinionDAO(EntityManager em) {
        super(PortletOpinionDO.class, em);
    }

    public List<PortletOpinionDO> selectOpinionByAccount(ContaDO contaDO) {
        throw new UnsupportedOperationException("Ainda não suportada...");
    }

    public List<PortletOpinionDO> selectOpinionByReferenced(PortletDO portletnDO) {
        throw new UnsupportedOperationException("Ainda não suportada...");
    }

    public PortletOpinionDO selectOpinionByReferencedAndAccount(PortletDO portletDO, ContaDO contaDO) {
        String jpql = "SELECT po FROM PortletOpinionDO po WHERE po.referenceId = :portletId AND po.account.id = :contaId";
        TypedQuery<PortletOpinionDO> query = entityManager.createQuery(jpql, PortletOpinionDO.class);
        query.setParameter("portletId", portletDO.getId());
        query.setParameter("contaId", contaDO.getId());
        PortletOpinionDO result = new PortletOpinionDO();
        try {
           result = query.getSingleResult();
        } catch (Exception e) {
            // TO-DO...
        }

        return result;
    }
}
